package com.bootdo.hjh.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.bootdo.hjh.domain.BonusFlag;
import com.bootdo.hjh.domain.CashPointsDO;
import com.bootdo.hjh.domain.Withdraw;

public interface PointsMapper {
	
	@Select("select sum(amount) from cash_points where user_id = #{userId}")
	public Integer cashPointsTotal(Long userId);
	
	@Select("select sum(amount) from product_points where user_id = #{userId}")
	public Integer productPointsTotal(Long userId);
	
	
	@Insert("insert into withdraw (user_id,amount,service_charge,exchange_amount,card_number,bank_name,card_user_name) "
			+ "values (#{userId},#{amount},#{serviceCharge},#{exchangeAmount},#{cardNumber},#{bankName},#{cardUserName})")
	public Integer addWithdraw(Withdraw withdraw);
	
	@Select("select * from bonus_flag where type = #{type} order by id desc limit 1")
	public BonusFlag getLastBonusFlag(Integer type);
	
	@Select("insert into bonus_flag (last_active_time,type) value(#{lastActiveTime},#{type})")
	public Integer saveLastBonusFlag(BonusFlag bonusFlag);
	
	@Select("select * from cash_points where type not in (1,2,9,0) and "
			+ " date(create_time) >= date(#{startDate}) and date(create_time) <= date(#{endDate}) ")
	public List<CashPointsDO> reportExpend(@Param("startDate") String startDate,@Param("endDate") String endDate);
	
	@Select("select sum(amount) from cash_points where user_id != 431")
	public Integer availableAmount();
	
	@Select("select sum(amount) from cash_points where type = 1")
	public Integer alreadyPresentedAmount();
	
}
